package com.uchengwang.ui.cm_ui.ucity.ui;

import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.uchengwang.R;
import com.uchengwang.functions.db.manager.LiteOrmDBUtil;
import com.uchengwang.functions.http.config.BaseConfig;
import com.uchengwang.functions.http.config.ClubConfig;
import com.uchengwang.functions.http.config.UCityConfig;
import com.uchengwang.functions.http.config.UniConfig;
import com.uchengwang.functions.http.entity.MapRequest;
import com.uchengwang.functions.http.listener.HttpCallBack;
import com.uchengwang.functions.http.listener.IHttpManager;
import com.uchengwang.functions.http.manager.HttpManager;
import com.uchengwang.functions.http.manager.OSSManager;
import com.uchengwang.ui.UChengApplication;
import com.uchengwang.ui.base_ui.ActivityTitleBar;
import com.uchengwang.ui.base_ui.ui.AllBaseActivity;
import com.uchengwang.ui.cm_ui.ucity.cityBean.UcityInfoBean;
import com.uchengwang.ui.cm_ui.ucity.listener.RxBusResultSubscriber;
import com.uchengwang.ui.cm_ui.ucity.listener.SortRichListener;
import com.uchengwang.ui.self.sortricheditor.view.editor.SEditorData;
import com.uchengwang.ui.self.sortricheditor.view.editor.SortRichEditor;
import com.uchengwang.ui.utils.DialogUtils;
import com.uchengwang.ui.utils.GetInfoUtils;
import com.uchengwang.ui.utils.JsonUtils;
import com.uchengwang.ui.utils.LoadingUtils;
import com.uchengwang.ui.utils.NetwotkUtil;
import com.uchengwang.ui.utils.UCommonUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import cn.finalteam.rxgalleryfinal.bean.MediaBean;
import cn.finalteam.rxgalleryfinal.rxbus.event.ImageMultipleResultEvent;
import cn.finalteam.rxgalleryfinal.ui.RxGalleryListener;
import me.shaohui.advancedluban.OnCompressListener;

/**
 * Created by U城网 on 2017/4/5.
 * 发布图文交叉信息
 */

public class ReleaseBenefitActivity extends AllBaseActivity implements View.OnClickListener{

    private SortRichEditor editor;
    private ImageView ivGallery;
    private Button btnPosts;
    private LinearLayout linear;
    private RelativeLayout addPhoto;
    private EditText rb_title;
    private int chooseImages = 0, MAX_NUM = 20;//已选中的图片数量 最多图片
    private List<MediaBean> beanList;
    private List<SEditorData> editList;//获得的编辑后的图文【按顺序】
    private int pubType;//1-U学，2-U赛，3-U行，4-U用，5-U公益活动倡议，6-U公益失物招领,7-社团活动, 8-社团分享) 9校吧帖子 100 军训日记【临时添加】
    private long pubType_id;//当发布帖子,社团分享时,需说明

    //上传图片成功后，将图片地址和文字拼接进一个String里,提交服务器保存
    private String stringContent = "";
    private String cover = "", shortDesc = "";//第一张图片地址 和第一段文字描述
    private boolean isCover = false, isShortDesc = false;//是否拿到第一张图片地址和第一段文字
    private String title_name;
    private ActivityTitleBar titleBar;
    private boolean isAllow = true;//防止多次提交
    private AlertDialog dialog;
    private boolean isAgainAccess = false;//重新编辑社团纳新
    private long recruitId;//社团纳新的ID
    private TextView rb_textNum;
    private boolean isHot;//是否发布到校园热门
    private String typeString;//某个子类型名称

    private UcityInfoBean infoBean;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_release_news);


        pubType = getIntent().getIntExtra(BaseConfig.PUB_TYPE, 0);
        pubType_id = getIntent().getLongExtra(BaseConfig.PUB_TYPE_ID, -1);
        isAgainAccess = getIntent().getBooleanExtra(BaseConfig.IS_AGAIN, false);//修改社团纳新
        recruitId = getIntent().getLongExtra(BaseConfig.RECRUIT_ID, -1);//修改修改社团纳新需要
        isHot = getIntent().getBooleanExtra(BaseConfig.IS_HOT, false);
        typeString = getIntent().getStringExtra(BaseConfig.TYPE_STRING);


        initView();

        //编辑内容时用到, 预防复制粘贴问题太多,将添加图片按钮挤下去
        TextWatcher watcher = new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence s, int i, int i1, int i2) {
                if(!TextUtils.isEmpty(s) && linear.getVisibility() == View.VISIBLE){
                    linear.setVisibility(View.GONE);
                    ivGallery.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        };

        switch (pubType){
            case BaseConfig.U_BENEFIT:
                titleBar.setTitle("发布公益信息", 0);
                editor.setTitle("请编辑公益内容", watcher);
                break;

            case BaseConfig.U_CLUB_SHARE:
                titleBar.setTitle("发布社团分享", 0);
                editor.setTitle("请编辑社团分享内容", watcher);
                break;
            case BaseConfig.U_SCHOOL_ARTICLE:
                titleBar.setTitle("发布校吧帖子", 0);
                editor.setTitle("请编辑帖子内容", watcher);
                break;
            case BaseConfig.CLUB_NEW_MEMBER:
                titleBar.setTitle("发布社团纳新", 0);
                editor.setTitle("请编辑纳新内容", watcher);
                break;
            case BaseConfig.U_JUNXUN:
                titleBar.setTitle("发布军训日记", 0);
                editor.setTitle("请编辑内容", watcher);
                break;
            case BaseConfig.U_HOT_ARTICLE:
                titleBar.setTitle("发布热文", 0);
                editor.setTitle("请编辑热文内容", watcher);
                break;
        }

        titleBar.setRightText("排序", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (editor.sort()) {
                    titleBar.getRightTV().setText("完成");
                } else {
                    titleBar.getRightTV().setText("排序");
                }

            }
        });

        titleBar.setLeftView("", 0, R.drawable.icon_black_back, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                back();
            }
        });

    }

    private void initView(){
        titleBar = (ActivityTitleBar) findViewById(R.id.rb_titleBa);

        editor = (SortRichEditor) findViewById(R.id.rb_richEditor);
        ivGallery = (ImageView) findViewById(R.id.rb_gallery);
        btnPosts = (Button) findViewById(R.id.rb_posts);

        rb_textNum = (TextView) findViewById(R.id.rb_textNum);
        rb_title = (EditText) findViewById(R.id.rb_title);
        rb_title.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence s, int i, int i1, int i2) {
                if (!TextUtils.isEmpty(s)){
                    rb_textNum.setText(s.length()+"/30");
                }else {
                    rb_textNum.setText("0/30");
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });

        linear = (LinearLayout) findViewById(R.id.rb_linear);
        addPhoto = (RelativeLayout) findViewById(R.id.rb_add);
        addPhoto.setOnClickListener(this);

        ivGallery.setOnClickListener(this);
        btnPosts.setOnClickListener(this);

        initData();

        initCreate();
    }

    /**
     * 初始化存储信息
     * */
    private void initCreate(){
        List<UcityInfoBean> list = LiteOrmDBUtil.getLiteOrm(this).getQueryByWhere(UcityInfoBean.class, "pubType", String.valueOf(pubType));
        if (list != null && list.size() >0){
            infoBean = list.get(0);
            if (infoBean != null && !TextUtils.isEmpty(infoBean.getPubDescription())){
                String desc = infoBean.getPubDescription();
                List<SEditorData> dataList = JsonUtils.getManager().parseList(desc, SEditorData.class);
                if (dataList == null || dataList.size() <=0 ){
                    return;
                }

                linear.setVisibility(View.GONE);
                ivGallery.setVisibility(View.VISIBLE);

                rb_title.setText(infoBean.getPubTitle());
                LinearLayout containerLayout = editor.getContentView();
                for (int i=0; i <dataList.size(); i++){//定义图片还是文字  0图片  1文字
                    SEditorData data = dataList.get(i);
                    if (data != null && !TextUtils.isEmpty(data.getType()) && data.getType().equals("0")){
                        File file = new File(data.getContent());
                        if (file!= null && file.exists()) {
                            RelativeLayout layout = editor.insertImageSave(data.getContent());
                            containerLayout.addView(layout);
                            chooseImages++;
                        }
                    }else if (data != null && !TextUtils.isEmpty(data.getType()) && data.getType().equals("1")){
                        EditText editText = editor.createEditText("");
                        editText.setText(data.getContent());
                        containerLayout.addView(editText);
                    }
                }
            }
            LiteOrmDBUtil.getLiteOrm(this).deleteWhere(UcityInfoBean.class, "pubType", String.valueOf(pubType));
        }
    }


    private void initData(){
        /**
         * 删除图标
         * */
        editor.setImageDeleteListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                RelativeLayout parentView = (RelativeLayout) view.getParent();
                editor.onImageDeleteClick(parentView);
                UCommonUtil.getUtil().showToast(ReleaseBenefitActivity.this, "delete");
                chooseImages--;
            }
        });

        /**
         * 查看大图
         * */
        editor.setLookBigListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                List<String> imageUrl = new ArrayList<String>();
                editList = editor.buildEditData();
                for (SEditorData data : editList){
                    //0图片  1文字
                    if (TextUtils.isEmpty(data.getType())){
                        continue;
                    }
                    if (data.getType().equals("0")){
                        imageUrl.add(data.getContent());
                    }
                }
                //选中的图片地址
                String url = (String) view.getTag();
                int index= 0;
                if (imageUrl != null && imageUrl.size() >0){
                    for (int i = 0; i< imageUrl.size(); i++){
                        if (url.equals(imageUrl.get(i))){
                            index = i;
                            break;
                        }
                    }

                    UCommonUtil.getUtil().startImagePagerActivity(ReleaseBenefitActivity.this, imageUrl, index, true);
                }
            }
        });


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rb_gallery:
                //添加图片
                addPhotos();
                break;
            case R.id.rb_posts:
                if (!NetwotkUtil.isConnectInternet()){
                    UCommonUtil.getUtil().showToast(this, "网络连接异常");
                    return;
                }

                title_name = rb_title.getText().toString();
                if (TextUtils.isEmpty(title_name)){
                    UCommonUtil.getUtil().showToast(this, "标题不能为空");
                    return;
                }
                if (chooseImages<1 && pubType != BaseConfig.U_JUNXUN){
                    UCommonUtil.getUtil().showToast(this, "请至少选择一张图片");
                    return;
                }
                editList = editor.buildEditData();
                // 下面的代码可以上传、或者保存，请自行实现
//                putEditData(editList);
                if (!isAllow){
                    UCommonUtil.getUtil().showToast(this, "正在提交,,,");
                    return;
                }
                isAllow = false;

                LoadingUtils.getUtils().loading(this);
                if (chooseImages<1){
                    //军训日记 没有发布图片
                    stringContent = JsonUtils.getManager().beanToString(editList);
                    putToHttp();
                }else {
                    cropmpress(editList);
                }

                break;
            case R.id.rb_add:
                //添加图片
               addPhotos();
                break;
        }
    }

    /**
     * 将图片压缩在上传
     * */
    private int position = 0;
    private List<SEditorData> cropmpress(final List<SEditorData> list){

        if (position >= list.size()){
            putEditData(list);
            return list;
        }
        final SEditorData data = list.get(position);
        if (TextUtils.isEmpty(data.getType()) || TextUtils.isEmpty(data.getContent())){
            list.remove(data);
            cropmpress(list);
            return null;

        }

        if (!data.getType().equals("0") || TextUtils.isEmpty(data.getContent())) {
            position++;
            cropmpress(list);
            return null;
        }
        final String path = data.getContent();
        UCommonUtil.getUtil().compressImageAlone(this, 300, path, new OnCompressListener() {
            @Override
            public void onStart() {

            }

            @Override
            public void onSuccess(File file) {
                Log.d("lll", "压缩="+position);
                Log.d("kkk", "原图地址="+path);
                Log.d("kkk", "压缩地址="+file.getAbsolutePath());
                list.get(position).setContent(file.getAbsolutePath());
                position++;

                if (position >= list.size()) {
                    putEditData(list);
                    return;
                }
                cropmpress(list);
            }
            @Override
            public void onError(Throwable e) {
                putEditData(list);//压缩失败直接上传原图
            }
        });
        return null;
    }


    /**
     * 负责处理编辑数据提交等事宜，请自行实现
     */

    private void putEditData(List<SEditorData> editList) {
        if (editList == null || editList.size() <= 0){
            UCommonUtil.getUtil().showToast(this, "请编辑公益内容");
            isAllow = true;
            return;
        }
        Log.d("lll", "开上");
        //图片上传阿里云oss后的返回
        OSSManager.getOSSManager().putSortRichImages(OSSManager.OSS_CITY, editList, new SortRichListener() {
            @Override
            public void onsuccess(List<SEditorData> list) {
                int size = list.size();

                if (list != null && size > 0){
                    //图文交叉排布的所有内容， 上传到我们服务器
                    stringContent = JsonUtils.getManager().beanToString(list);

                    for (int i = 0; i < size; i++) {
                        SEditorData data = list.get(i);//0图片  1文字
                        if (data.getType().equals("1") && !TextUtils.isEmpty(data.getContent()) && !isShortDesc) {
                            shortDesc = data.getContent();
                            if (shortDesc.length() >40){
                                shortDesc = shortDesc.substring(0, 40);
                            }
                            isShortDesc = true;
                            Log.d("RichEditor", "commit inputStr=" + data.getContent());
                        }
                        if (data.getType() .equals("0") && !TextUtils.isEmpty(data.getContent()) && !isCover) {
                            cover = data.getContent();
                            isCover = true;
                            Log.d("RichEditor", "commit imgePath=" + data.getContent());
                        }
                        if (isShortDesc && isCover){
                            break;
                        }
                    }

                    switch (pubType){
                        case BaseConfig.U_BENEFIT://校园公益
                        case BaseConfig.U_CLUB_SHARE://社团分享
                        case BaseConfig.U_SCHOOL_ARTICLE://校吧帖子
                        case BaseConfig.U_HOT_ARTICLE:
                        case BaseConfig.U_JUNXUN://军训日记
                            putToHttp();
                            break;

                        case BaseConfig.CLUB_NEW_MEMBER://社团纳新
                            putClubAccess();
                            break;
                    }
                }
            }
            @Override
            public void onFailure(String message) {
                isAllow = true;
                LoadingUtils.getUtils().hide();
            }
        });
    }

    /**
     * 信息提交到服务器 校园公益 社团分享 校吧帖子  临时的军训日记
     * */
    private void putToHttp(){
        Log.d("lll", "开始上传");

        if (TextUtils.isEmpty(stringContent)){
            UCommonUtil.getUtil().showToast(this, "内容不能为空");
            isAllow = true;
            return;
        }

        int pubItemType = 0;
        switch (pubType){
            case BaseConfig.U_HOT_ARTICLE://获取热文的子类型type
                pubItemType = GetInfoUtils.getUtils().getHotArticle(typeString);
                break;
        }

        MapRequest map = new MapRequest();
        map.put(BaseConfig.PUB_TYPE, pubType);
        map.put(BaseConfig.PUB_TITLE, title_name);
        if (pubItemType >0){
            map.put(BaseConfig.PUB_ITEM_TYPE, pubItemType);
        }

        map.put(BaseConfig.PUB_DESCRIPTION, stringContent);
        map.put(BaseConfig.PUB_SHORT_COVER, cover);//背景图
        map.put(BaseConfig.PUB_SHORT_DESC, shortDesc);
        map.put(BaseConfig.CITY_NAME, "杭州");
        if (UChengApplication.myUniId >0){
            map.put(BaseConfig.UNI_ID, UChengApplication.myUniId);
            if (!TextUtils.isEmpty(UChengApplication.mySchoolName)){
                map.put(BaseConfig.UNI_NAME, UChengApplication.mySchoolName);
            }
        }else {//针对几个更大权限的uni号, 虽然后台默认认证了, 但是没有大学ID, 那么切换到那个大学, 上传信息就归属那个大学
            map.put(BaseConfig.UNI_ID, UChengApplication.uniId);
            map.put(BaseConfig.UNI_NAME, UChengApplication.schoolName);
        }
        map.put(BaseConfig.USER_AVATAR, UChengApplication.userAvatar);

        if (pubType_id >0){
            //说明发布来源社团发布和校吧板块发布
            map.put(BaseConfig.PUB_TYPE_ID, pubType_id);
        }else {
            map.put(BaseConfig.UID, UCommonUtil.getUtil().getId());
        }

        release(map);

    }

    /**
     * 是否发布到校园热门
     * */
    private void release(MapRequest map){
        if (isHot){
            //发布到热门
            HttpManager.newInstance(this).query(UniConfig.ReleaseHot.method, UniConfig.ReleaseHot.URL, map, new HttpCallBack() {
                @Override
                public void onError(int status, String msg) {
                    LoadingUtils.getUtils().hide();
                    isAllow = true;
                    Log.d("jjf", "发布信息=status="+status+"==msg=="+msg);
                    UCommonUtil.getUtil().showToast(ReleaseBenefitActivity.this, "提交失败, 请重试");
                }

                @Override
                public void onResp(int status,  String msg, String data) {
                    LoadingUtils.getUtils().hide();
                    Log.d("jjf", "发布信息=status="+status+"==msg=="+msg);
                    if (status != 0){
                        isAllow = true;
                        UCommonUtil.getUtil().showToast(ReleaseBenefitActivity.this, "提交失败");
                        return;
                    }
                    UCommonUtil.getUtil().showToast(ReleaseBenefitActivity.this, "发布成功");
                    switch (pubType){
                        case BaseConfig.U_BENEFIT://校园公益
                        case BaseConfig.U_CLUB_SHARE://社团分享
                        case BaseConfig.U_SCHOOL_ARTICLE://校吧帖子
                        case BaseConfig.U_JUNXUN://军训日记
                            BaseConfig.isRelease = true;//刷新

                            break;
                        case BaseConfig.U_HOT_ARTICLE:
                            BaseConfig.isBanerRelease = true;//刷新
                            break;
                    }
                    ReleaseBenefitActivity.this.finish();
                }
            });

        }else {
            HttpManager.newInstance(this).query(UCityConfig.Ucity.method_release, UCityConfig.Ucity.URL, map, new HttpCallBack() {
                @Override
                public void onError(int status, String msg) {
                    LoadingUtils.getUtils().hide();
                    isAllow = true;
                    Log.d("jjf", "发布公益信息失败=status="+status+"==data=="+msg);
                    UCommonUtil.getUtil().showToast(ReleaseBenefitActivity.this, "提交失败");
                }

                @Override
                public void onResp(int status,  String msg, String data) {
                    LoadingUtils.getUtils().hide();
                    Log.d("jjf", "发布公益信息=status="+status+"==data=="+msg);

                    isAllow = true;
                    if (status ==0){
                        UCommonUtil.getUtil().showToast(ReleaseBenefitActivity.this, getString(R.string.release_success));
                        switch (pubType){
                            case BaseConfig.U_BENEFIT:
//                                SchoolNewsActivity.lostBenefitRefresh = BaseConfig.U_BENEFIT;
                                break;
                            default:
                                BaseConfig.isRelease = true;
                                break;
                        }
                        ReleaseBenefitActivity.this.finish();
                    }else {
                        UCommonUtil.getUtil().showToast(ReleaseBenefitActivity.this, "发布失败");
                    }
                }
            });
        }
    }

    /**
     * 发布社团纳新到服务器
     * */
    private void putClubAccess(){
        Log.d("lll", "开始上传");

        if (TextUtils.isEmpty(stringContent)){
            UCommonUtil.getUtil().showToast(this, "内容不能为空");
            isAllow = true;
            return;
        }

        MapRequest map = new MapRequest();
        map.put(BaseConfig.IS_ACTIVI, true);
        map.put(BaseConfig.RECRUIT_TITLE, title_name);
        map.put(BaseConfig.RECRUIT_DESCRIPTION, stringContent);
        map.put(BaseConfig.COVER, cover);//背景图
        map.put(BaseConfig.NEED_LIMIT, 100);

        IHttpManager.RequestMethod method = null;
        if (isAgainAccess){
            //之前有过有过纳新 现在修改
            method = ClubConfig.ClubAccess.method_change;
            if (recruitId >0){
                map.put(BaseConfig.UPDATE_ID, recruitId);
            }
        }else {
            method = ClubConfig.ClubAccess.method_create;
        }


        HttpManager.newInstance(this).query(method, ClubConfig.ClubAccess.URL, map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                LoadingUtils.getUtils().hide();
                isAllow = true;
                Log.d("jjf", "发布社团纳新失败=status="+status+"==data=="+msg);
                UCommonUtil.getUtil().showToast(ReleaseBenefitActivity.this, "提交失败");
            }

            @Override
            public void onResp(int status,  String msg, String data) {
                LoadingUtils.getUtils().hide();
                Log.d("jjf", "发布公益信息=status="+status+"==data=="+msg);
                isAllow = true;
                if (status ==0){
                    UCommonUtil.getUtil().showToast(ReleaseBenefitActivity.this, "发布成功");
                    BaseConfig.isRelease = true;
                    ReleaseBenefitActivity.this.finish();
                }else {
                    UCommonUtil.getUtil().showToast(ReleaseBenefitActivity.this, "发布失败");
                }
            }
        });
    }

    private void addPhotos(){
        if (chooseImages >= MAX_NUM){
            UCommonUtil.getUtil().showToast(this, "最多只可以上传"+MAX_NUM+"张图片");
            return;
        }
        UCommonUtil.getUtil().openGalleryMultiple(this, MAX_NUM-chooseImages, new RxBusResultSubscriber<ImageMultipleResultEvent>() {
            @Override
            public void onEvent(ImageMultipleResultEvent imageMultipleResultEvent)   {
               beanList = imageMultipleResultEvent.getResult();

                if (beanList != null && beanList.size()>0){
                    linear.setVisibility(View.GONE);
                    ivGallery.setVisibility(View.VISIBLE);

                    int num = beanList.size();
                    chooseImages = chooseImages + num;

                    String[] urls = new String[num];

                    for (int i=0; i<num; i++){
                        String bigPath = beanList.get(i).getThumbnailBigPath();
                        if (TextUtils.isEmpty(bigPath)){
                            urls[i] = beanList.get(i).getOriginalPath();
                        }else {
                            urls[i] = bigPath;
                        }
                    }
                    editor.addImageArray(urls);
                }
            }
        }, null,null);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        RxGalleryListener.getInstance().setMultiImageCheckedListener(null);
    }

    @Override
    public void onBackPressed() {
        back();
    }

    /**
     * 返回键
     * */
    private void back(){
        UCommonUtil.getUtil().hideSoftInput(this, rb_title);

        if (!TextUtils.isEmpty(rb_title.getText().toString()) || chooseImages >0){
            dialog = DialogUtils.getUtils().showDialogAll(this, false, "确定要退出吗?", "退出并保存信息?", "继续编辑", "退出", new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    DialogUtils.getUtils().cancel();

                    UcityInfoBean ucityInfoBean = new UcityInfoBean();
                    ucityInfoBean.setPubType(pubType);
                    ucityInfoBean.setPubTitle(rb_title.getText().toString());
                    List<SEditorData> list = editor.buildEditData();
                    stringContent = JsonUtils.getManager().beanToString(list);
                    ucityInfoBean.setPubDescription(stringContent);

                    LiteOrmDBUtil.getLiteOrm(ReleaseBenefitActivity.this).getLiteOrm(ReleaseBenefitActivity.this).insert(ucityInfoBean);

                    ReleaseBenefitActivity.this.finish();
                }
            }, null);

        }else {
            this.finish();
        }
    }


}
